HAL CORDIC Use Cases

Full CORDIC Initialization Sequence

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "HAL CORTEX\n(NVIC)" as p3
participant "<font color=red><b>HAL DMA</b></font>" as p4
participant "HAL RCC" as p5

== HAL Initialization  ==
p1->p5 : HAL_Init
p5 --> p1: HAL_OK
p1->p5 : Configure system clock
p5-->p1: HAL_OK
==CORDIC HAL Initialization  ==
p1 -> p2 : HAL_CORDIC_Init
alt#grey #lightgrey If USE_HAL_CORDIC_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO
p2->p5 : Enable the CORDIC clock
p5-->p2
end
hnote over p2 : global_state=INIT
p1 <-- p2 : HAL_OK

==CORDIC System Initialization==
Note over p2 : CORDIC System initialization can be called before\nCORDIC HAL initialization

alt#grey #lightgrey If Interrupt needed
p1->p3 : Enable needed Interrupt
p3-->p1
end

alt#grey #lightgrey If USE_HAL_CORDIC_DMA == 1
p1->p4 : Initialization of DMA
p4-->p1
p1->p2 : HAL_CORDIC_SetWriteDMA / HAL_CORDIC_SetReadDMA
p4-->p1
end

alt#grey #lightgrey If USE_HAL_CORDIC_CLK_ENABLE_MODEL == HAL_CLK_ENABLE_NO
p1->p5 : Enable the CORDIC clock
p5 --> p1
end

@enduml

Functions called:

Full CORDIC Deinitialization Sequence

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "HAL CORTEX\n(NVIC)" as p3
participant "HAL RCC" as p4
participant "<font color=red><b>HAL DMA</b></font>" as p5

==CORDIC DeInitialisation==
p1->p2 : HAL_CORDIC_DeInit
hnote over p2 : global_state=RESET
p1<--p2 : HAL_OK

==CORDIC system DeInitalization==

alt#grey #lightgrey If Interrupt needed
p1->p3 : Disable needed Interrupt
p3-->p1
end

alt#grey #lightgrey If USE_HAL_CORDIC_DMA == 1
p1->p5 : DeInitialization of DMA
p5-->p1
end

p1->p4 : Disable the CORDIC clock
p4 --> p1
@enduml

Functions called:

User Application Configuration

@startuml

' To add a number by line
'autonumber

' Fix order of each column
participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2


== CORDIC HAL configuration ==
p1->p2 : HAL_CORDIC_SetConfig()
note right : configure the peripheral \n Global state = IDLE
p2-->p1
alt#grey #lightgrey optional

p1 -> p2 : HAL_CORDIC_SetFunction()
note right: set the mathematical function
p2 --> p1 
p1 -> p2 : HAL_CORDIC_SetInputWidth()
note right: set the width (16bits or 32bits) of the input data
p2 --> p1
p1 -> p2 : HAL_CORDIC_SetOutputWidth()
note right: set the width (16bits or 32bits) of the output data
p2 --> p1
p1 -> p2 : HAL_CORDIC_SetNumberArguments()
note right: set the number of arguments of the function
p2 --> p1
p1 -> p2 : HAL_CORDIC_SetNumberResults()
note right: set the number of results of the function
p2 --> p1
p1 -> p2 : HAL_CORDIC_SetPrecision()
note right: set the precision required
p2 --> p1
p1 -> p2 : HAL_CORDIC_SetScalingFactor()
note right: set the scaling factor
p2 --> p1
end
@enduml

Functions called:

Process Calculate Polling

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<b>IP CORDIC</b>" as p3


== CORDIC HAL Calculate in Polling mode ==

p1->p2: HAL_CORDIC_Calculate
hnote over p2 : global_state= ACTIVE
p2->p3: Write data to IP Cordic

Note over p2#lightyellow: The CORDIC driver runs a calculation\n using the polling mode.

loop until all data write or timeout
p2->p3: Write data to IP Cordic [anticipated write]
activate p2
activate p3
p2->p2 : Read until RRDY flag raised
p2->p3 : Read data from IP Cordic
p2-> p2 : Store data
p2[#FFFFFF]-> p3
deactivate p3
deactivate p2
end

Note over p2#lightyellow: (n) calculus were done but (n-1) results were read.\n so another read is needed to get the last result.

p2[#FFFFFF]-> p3
activate p2
activate p3
p2->p3 : Read data from IP Cordic [read last result]
p2->p2: store last result
p2[#FFFFFF]-> p3
deactivate p2
deactivate p3
hnote over p2 : global_state= IDLE \nAll data has been processed
p2 -->p1 : HAL_OK 


@enduml

Functions called:

Process Calculate Zero Overhead

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<font color=red><b>IP CORDIC</b></font>" as p3


== CORDIC HAL Calculate in ZeroOverhead mode ==
p1->p2: HAL_CORDIC_CalculateZeroOverhead
hnote over p2 : global_state= ACTIVE
p2->p3: Write data to IP Cordic


Note over p2#lightyellow: The CORDIC driver runs a calculation\n using the Zero-Overhead mode.

loop until all data write or timeout
p2 -> p3 : Write data to IP Cordic
activate p2
activate p3
p3 --> p2 :
p2->p3: Read data from IP Cordic
p3->p3: insert wait states
p3-->p2:
p2 -> p2 : read and store data
p2[#FFFFFF]-> p3
deactivate p3
deactivate p2
end

Note over p2#lightyellow: (n) calculus were done but (n-1) results were read.\n so another read is needed to get the last result.

p2[#FFFFFF]-> p3
activate p2
activate p3
p2->p3 : Read data from IP Cordic [read last result]
p3->p3: insert wait states
p3-->p2:
p2->p2: store last result
p2[#FFFFFF]-> p3
deactivate p2
deactivate p3
hnote over p2 : global_state= IDLE \nAll data has been processed
p2 -->p1 : HAL_OK

@enduml

Functions called:

Process Calculate Interrupt

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<font color=red><b>IP CORDIC</b></font>" as p3
participant "HAL CORTEX (NVIC)" as p4
participant "HW" as p5

== CORDIC HAL Calculate in Interrupt mode ==
p1->p2: HAL_CORDIC_Calculate_IT
hnote over p2 : global_state= ACTIVE

note over p2 : Enable CORDIC interruption
p2->p3 : Write Data to CORDIC
p3-->p2:

p2-->p1: HAL_OK

loop Data Ready flag raised

p4<-p5: CORDIC_IRQn
p4->p2: HAL_CORDIC_IRQHandler 
activate p2
p2->p3: Read data from Cordic
p2->p3: Write data to Cordic 
p2->p2 : Store results
p2[#FFFFFF]->p3:
deactivate p2
end
note over p2 : Disable CORDIC interruption
hnote over p2 : global_state= IDLE
p2->p1: HAL_CORDIC_CalculateCpltCallback

@enduml

Functions called:

Process Calculate DMA

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<font color=red><b>HAL DMA</b></font>" as p4
participant "HAL CORTEX (NVIC)" as p5
participant "HW" as p6


== CORDIC HAL Calculate DMA mode (dma in/out) ==
p1->p2:HAL_CORDIC_SetReadDMA
p2-->p1: HAL_OK
p1->p2:HAL_CORDIC_SetWriteDMA
p2-->p1: HAL_OK
p1->p2: HAL_CORDIC_Calculate_DMA
hnote over p2 : global_state= ACTIVE
p2->p4:HAL_DMA_StartPeriphXfer_Opt(dma_out)
p4-->p2: HAL_OK
note over p2 : Enable DMA Read request
p2->p4 :HAL_DMA_StartPeriphXfer_Opt(dma_in)
p4-->p2: HAL_OK
note over p2 : Enable DMA Write request
p2-->p1: HAL_OK

p5<-p6   : DMAWR complete interrupt
p5->p4 : HAL_DMA_IRQHandler
p4->p2 : CORDIC_DMAInCplt

p2-->p4
p4-->p6
alt Write complete
note over p2 : Disable CORDIC Write request
p2->p1 : HAL_CORDIC_WriteCpltCallback
p1-->p2
end
p5<-p6   : DMARD complete interrupt
p5->p4 : HAL_DMA_IRQHandler
p4->p2 : CORDIC_DMAOutCplt

p2-->p4
p4-->p6
alt calculation complete
note over p2 : Disable CORDIC Read request
p2->p1 : HAL_CORDIC_CalculateCpltCallback
p1-->p2
hnote over p2 : global_state= IDLE
end 


@enduml

Functions called:

Peripheral Write

@startuml

participant "<b>User application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<font color=green><b>HAL ADC</b></font>" as ADC
participant "<font color=red><b>HAL DMA</b></font>" as p3
participant "DMAx_IRQHandler" as p4
participant "HW" as p5

== input CORDIC WDATA register managed directly by peripheral\n - output managed with DMA process ==

note over p1 : Set the function to use with appropriate\n arguments and results settings
p1 -> p2 : HAL_CORDIC_SetConfig
hnote over p2 : global_state= IDLE
p1 <-- p2 :HAL_OK

p1 -> p2 : HAL_CORDIC_SetReadDMA
p1 <-- p2 :HAL_OK

p1 -> p2 : HAL_CORDIC_Read_DMA
p2->p3:HAL_DMA_StartPeriphXfer_Opt(dma_out)
p3-->p2: HAL_OK
hnote over p2 : global_state= ACTIVE
p1 <-- p2 :HAL_OK
p1->ADC : HAL_ADC_SetConfig()
p1->ADC : HAL_ADC_Start()
p1->ADC : HAL_ADC_Calibrate()
note over p1 : Get Cordic WDATA Register address.
p1 -> p2 : HAL_CORDIC_GetWriteAddress
p1 <-- p2 : (CORDIC_WDATA address)
p1->ADC : HAL_ADC_REG_<color:red>StartConv_DMA</color>(<handle>, <buff_adr>, <buff_size>) / _DMA_Opt()

loop 

   p4 <-p5    : DMAx complete interrupt
   p4 -> p3 : HAL_DMA_IRQHandler
   p3 -> ADC : Callback function pointer
   ADC-> p1  : HAL_ADC_REG_DataTransferCpltCallback
   p3 <-- ADC
   p4 <-- p3
   p4 -->p5
end

loop 
   p4 <-p5    : DMAx half complete interrupt
   p4 -> p3 : HAL_DMA_IRQHandler
   p3 -> p2 : XferCpltCallback
   p2-> p1 : HAL_CORDIC_ReadHalfCpltCallback
   p3 <-- p2
   p4 <-- p3
   p4 -->p5

   p4 <-p5    : DMAx complete interrupt
   p4 -> p3 : HAL_DMA_IRQHandler
   p3 -> p2 : XferCpltCallback
   p2-> p1  : HAL_CORDIC_CalculateCpltCallback
   p3 <-- p2
   p4 <-- p3
   p4 -->p5
end
p1->ADC : HAL_ADC_REG_<color:red>StopConv_DMA</color>()
return
p1->ADC : HAL_ADC_Stop()
@enduml

Functions called:

Process Abort Transfer Blocking

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<font color=red><b>HAL DMA</b></font>" as p3

== CORDIC HAL Abort ==
p1->p2: HAL_CORDIC_Abort
hnote over p2 : global_state= ABORT
alt#grey #lightgrey USE_HAL_CORDIC_DMA
note over p2 : Disable CORDIC DMA request
p2->p3: HAL_DMA_Abort
p3-->p2: HAL_OK
end
note over p2 : Disable interrupts

hnote over p2 : global_state= IDLE
p2-->p1: HAL_OK


@enduml

Functions called:

Process Abort Transfer IT Non-Blocking

@startuml

participant "<b>User Application</b>" as p1
participant "<font color=green><b>HAL CORDIC</b></font>" as p2
participant "<font color=red><b>HAL DMA</b></font>" as p3
participant "NVIC" as p4
participant "HW" as p5

== CORDIC HAL Abort IT ==
p1->p2: HAL_CORDIC_Abort_IT
hnote over p2 : global_state= ABORT
alt#grey #lightgrey USE_HAL_CORDIC_DMA

p2->p3: HAL_DMA_Abort_IT
p3-->p2: HAL_OK


p5 -->p4 :interrupt
p3<--p4: DMAx Abort Interrupt
p3-->p2: CORDIC_DMA Abort
note over p2: Disable CORDIC DMA request
p2->p1: HAL_CORDIC_AbortCpltCallback
p1-->p2
end
note over p2: Disable interrupts
hnote over p2 : global_state= IDLE
p2->p1: HAL_CORDIC_AbortCpltCallback
p1-->p2
p2-->p1: HAL_OK
@enduml

Functions called: